﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Types;

namespace Client
{
    public partial class SearchResultAnswerForm : Form
    {
        public delegate void UpdateFileContentDelegate(string fileContent);
        public delegate void UpdateCourseNameDelegate(string courseName);
        public delegate void UpdateQuestionSummaryDelegate(string questionSummary);

        public SearchResultAnswerForm(AnswerType answer)
        {
            InitializeComponent();
            idTextBox.Text = answer.id.ToString();
            summaryRichTextBox.Text = answer.summary;
            filePathTextBox.Text = answer.filePath;
            dateTextBox.Text = answer.date.ToString();
            ClientManager.Instance.updateFileContent += new ClientManager.UpdateFileContent(this.UpdateFileContent);
            ClientManager.Instance.updateCourseName += new ClientManager.UpdateCourseName(this.UpdateCourseName);
            ClientManager.Instance.updateQuestionSummary += new ClientManager.UpdateQuestionSummary(this.UpdateQuestionSummary);
        }

        private void UpdateFileContent(string fileContent)
        {
            if (InvokeRequired)
            {
                Invoke(new UpdateFileContentDelegate(this.UpdateFileContent), fileContent);
            }
            else
            {
                fileContentRichTextBox.Text = fileContent;
            }
        }

        private void UpdateCourseName(string courseName)
        {
            if (InvokeRequired)
            {
                Invoke(new UpdateCourseNameDelegate(this.UpdateCourseName), courseName);
            }
            else
            {
                courseTextBox.Text = courseName;
            }
        }

        private void UpdateQuestionSummary(string questionSummary)
        {
            if (InvokeRequired)
            {
                Invoke(new UpdateQuestionSummaryDelegate(this.UpdateQuestionSummary), questionSummary);
            }
            else
            {
                questionSummaryRichTextBox.Text = questionSummary;
            }
        }
    }
}
